package com.jmz.apt.api.Provider;

import com.jmz.apt.api.Utils.MD5Util;
import com.jmz.apt.api.entity.dbEntity.JmzAdminUser;
import com.jmz.apt.api.entity.dbEntity.TimeTygp;
import com.jmz.apt.api.message.request.Condition;
import com.jmz.apt.api.message.request.Query;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;

import java.util.List;

public class TimeTygpProvider extends BaseProvider {

    public String getCount(List<Condition> conditions) {
        return super.count(conditions);
    }

    public String select(String columns, List<Condition> condition, Query query) {
        return  super.findAll(columns,condition,query);
    }

    public String getTableName(){
        return "time_tygp";
    }

    public String insert(TimeTygp timeTygp) {
        SQL sql = new SQL();
        sql.INSERT_INTO(getTableName());
        if (timeTygp.getName() != null) {
            sql.VALUES("name", "#{name}");
        }
        if (timeTygp.getStartTime() != null) {
            sql.VALUES("start_time", "#{startTime}");
        }
        if (timeTygp.getEndTime() != null) {
            sql.VALUES("end_time", "#{endTime}");
        }
        if (timeTygp.getCreateTime() != null) {
            sql.VALUES("create_time", "#{createTime}");
        }
        if (timeTygp.getUpdateTime() != null) {
            sql.VALUES("update_time", "#{updateTime}");
        }
        return sql.toString();
    }


    public String selectOne(TimeTygp timeTygp) {
        SQL sql = new SQL();
        sql.SELECT("*");
        sql.FROM(getTableName());
        if (timeTygp.getId() != null) {
            sql.WHERE("id=#{id}");
        }
        String lastSql = sql.toString();
        System.out.println(lastSql);
        return lastSql + "limit 1";
    }

    public String delete(TimeTygp timeTygp) {
        return new SQL() {{
            DELETE_FROM(getTableName());
            WHERE("id = #{id}"); //暂时禁止批量删除
        }}.toString();
    }

    public String update(TimeTygp timeTygp) {
        return new SQL() {{
            UPDATE(getTableName());
            if (timeTygp.getName() != null) {
                SET("name = #{name}");
            }
            if(timeTygp.getStartTime() != null) {
                SET("start_time = #{startTime}");
            }
            if(timeTygp.getEndTime() != null) {
                SET("start_time = #{endTime}");
            }
            WHERE("id = #{id}");
        }}.toString();
    }
}
